/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

/**
 * https://leetcode-cn.com/problems/middle-of-the-linked-list/
 * 链表的中间节点
 * @param head 
 */
const middleNode = (head: ListNode | null): ListNode | null => {
    // 边界判断
    if (head === null || head.next === null) return head;

    let slow: ListNode = head,
        fast: ListNode | null = head;
    while (fast !== null && fast.next !== null ) {
        slow = slow.next!;
        fast = fast.next.next;
    }

    return slow

};